﻿using Microsoft.Practices.Composite.Events;
using Microsoft.Practices.Composite.Regions;
using Microsoft.Practices.Composite.Wpf.Events;
using RAD.Infrastructure;
using RAD.Modules.UI.Interfaces;

namespace RAD.Modules.UI.Controllers
{
    /// <summary>
    /// Контроллер панели управления. 
    /// </summary>
    public class ToolbarController : IToolbarController
    {
        private readonly IRegionManager _regionManager;
        private readonly IEventAggregator _eventAggregator;
        private readonly IAboutViewPresenter _aboutViewPresenter;

        public ToolbarController(IRegionManager regionManager, IEventAggregator eventAggregator,
                                 IAboutViewPresenter aboutViewPresenter)
        {
            _regionManager = regionManager;
            _eventAggregator = eventAggregator;
            _aboutViewPresenter = aboutViewPresenter;
        }

        #region IToolbarController Members

        public void AboutViewShow(string parameter)
        {
            _aboutViewPresenter.ShowView();
        }

        public void ApplicationExit()
        {
            System.Windows.Application.Current.Shutdown();
        }

        public void Run()
        {
            _eventAggregator.GetEvent<AboutViewShowEvent>().Subscribe(AboutViewShow, ThreadOption.UIThread);
        }

        #endregion
    }
}